<template>
	<view class="container">
		<view class="addrInfoView">
			<view class="addrItem" @click="addrItemTap(item, index)" v-for="(item, index) of itemList" :key='index'>
				<view class="left">
					<!-- <u-icon name="checkbox-mark" size='36rpx' color='#a8cd03'></u-icon> -->
				</view>
				<view class="center">
					<view class="contactInfo">
						<view class="default" v-if="item.default">默认</view>
						<text>{{item.contactName}}</text>
						<text>{{item.contactPhone}}</text>
					</view>
					<view class="addrInfo">
						<text>{{item.addrInfo}}</text>
					</view>
				</view>
				<view class="right" @click.stop="editAddrItem(item, index)" >
					<u-icon  name="edit-pen" size='50rpx' color='#d4a781'></u-icon>
				</view>
			</view>
		</view>
		
		<view class="footer safeArea">
			<view style="width: 670rpx;"><u-button @click='addAction' type="error">新增收货地址</u-button></view>
		</view>
		
	</view>
</template>

<script>
	import {addr} from '@/api/addr.js'
	export default{
		data() {
			return {
				itemList: []
			}
		},
		onShow() {
			this.findAddrList()
		},
		methods:{
			findAddrList(){
				addr.findAddrList().then(res => {
					if(res.data.code == 10000){
						var itemList = res.data.data.list
						for(var item of itemList){
							item.addrInfo = item.area.replace(/，/g,' ') + '  ' + item.detailAddr
						}
						this.itemList = itemList
					}
				})
			},
			addAction(){
				this.$Router.push({
					name: 'addr'
				})
			},
			//去编辑收货地址
			editAddrItem(item, index){
				this.$Router.push({
					name: 'addr',
					params: {
						addrInfo: JSON.stringify(item)
					}
				})
			},
			//选择收货地址
			addrItemTap(item, index){
				uni.navigateBack();
				var pages = getCurrentPages();
				var prevPage = pages[pages.length - 2]; //上一个页面
				prevPage.$vm.selectAddrInfoBack(encodeURIComponent(JSON.stringify(item)))
			},
		}
	}
</script>

<style lang="scss" scoped>
	.container{
		background-color: #FFFFFF;
		height: 100vh;
	}
	.addrInfoView{
		display: flex;
		flex-direction: column;
		.addrItem{
			display: flex;
			flex-direction: row;
			align-items: center;
			padding: 30rpx;
			border-bottom: 1px solid #EFEFEF;
			.left{
				flex-shrink: 0;
			}
			.center{
				width: 100%;
				.contactInfo{
					display: flex;
					flex-direction: row;
					align-items: center;
					.default{
						background-color: #FC5E53;
						color: #FFFFFF;
						font-size: 20rpx;
						padding: 0 8rpx;
						font-weight: bold;
					}
					text:nth-of-type(1){
						margin-left: 10rpx;
					}
					text:nth-of-type(2){
						margin-left: 40rpx;
					}
				}
				.addrInfo{
					font-size: 30rpx;
					font-weight: bold;
					margin-top: 10rpx;
				}
			}
			.right{
				flex-shrink: 0;
			}
		}
	}
	.footer{
		width: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		position: fixed;
		bottom: 0;
		height: 140rpx;
	}
</style>
